﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:APP_PROFORHOUINFO
	/// </summary>
	public partial class APP_PROFORHOUINFO : BaseDAL<GSLMS.Entity.TB_APP_PROFORHOUINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public APP_PROFORHOUINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_APP_PROFORHOUINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_REGINFOID", model.REGINFOID),
								new OracleParameter("P_TRADEBY", model.TRADEBY),
								new OracleParameter("P_FORHOUTYPE", model.FORHOUTYPE),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_HOUADD", model.HOUADD),
								new OracleParameter("P_TENRIGHT", model.TENRIGHT),
								new OracleParameter("P_TENBANK", model.TENBANK),
								new OracleParameter("P_TENSUBBACK", model.TENSUBBACK),
								new OracleParameter("P_TENENDDATE", model.TENENDDATE),
								new OracleParameter("P_TENLEFTAMT", model.TENLEFTAMT),
								new OracleParameter("P_HOUPRICE", model.HOUPRICE),
								new OracleParameter("P_HOUTOTALPRICE", model.HOUTOTALPRICE),
								new OracleParameter("P_DOWNPAYAMT", model.DOWNPAYAMT),
								new OracleParameter("P_FIRSTPAYAMT", model.FIRSTPAYAMT),
								new OracleParameter("P_PAYMOD", model.PAYMOD),
								new OracleParameter("P_PAYBANK", model.PAYBANK),
								new OracleParameter("P_PAYSUBBANK", model.PAYSUBBANK),
								new OracleParameter("P_PROMISEAMT", model.PROMISEAMT),
								new OracleParameter("P_COUGUA1", model.COUGUA1),
								new OracleParameter("P_VERIFILD1", model.VERIFILD1),
								new OracleParameter("P_COUGUA2", model.COUGUA2),
								new OracleParameter("P_VERIFILD2", model.VERIFILD2),
								new OracleParameter("P_SIGNMAN", model.SIGNMAN),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 28; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_proforhouinfo_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_APP_PROFORHOUINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_REGINFOID", model.REGINFOID),
								new OracleParameter("P_TRADEBY", model.TRADEBY),
								new OracleParameter("P_FORHOUTYPE", model.FORHOUTYPE),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_HOUADD", model.HOUADD),
								new OracleParameter("P_TENRIGHT", model.TENRIGHT),
								new OracleParameter("P_TENBANK", model.TENBANK),
								new OracleParameter("P_TENSUBBACK", model.TENSUBBACK),
								new OracleParameter("P_TENENDDATE", model.TENENDDATE),
								new OracleParameter("P_TENLEFTAMT", model.TENLEFTAMT),
								new OracleParameter("P_HOUPRICE", model.HOUPRICE),
								new OracleParameter("P_HOUTOTALPRICE", model.HOUTOTALPRICE),
								new OracleParameter("P_DOWNPAYAMT", model.DOWNPAYAMT),
								new OracleParameter("P_FIRSTPAYAMT", model.FIRSTPAYAMT),
								new OracleParameter("P_PAYMOD", model.PAYMOD),
								new OracleParameter("P_PAYBANK", model.PAYBANK),
								new OracleParameter("P_PAYSUBBANK", model.PAYSUBBANK),
								new OracleParameter("P_PROMISEAMT", model.PROMISEAMT),
								new OracleParameter("P_COUGUA1", model.COUGUA1),
								new OracleParameter("P_VERIFILD1", model.VERIFILD1),
								new OracleParameter("P_COUGUA2", model.COUGUA2),
								new OracleParameter("P_VERIFILD2", model.VERIFILD2),
								new OracleParameter("P_SIGNMAN", model.SIGNMAN),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 28; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_proforhouinfo_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_proforhouinfo_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_APP_PROFORHOUINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_APP_PROFORHOUINFO model = new GSLMS.Entity.TB_APP_PROFORHOUINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["REGINFOID"]!=null && dr["REGINFOID"].ToString()!="")
				{
					model.REGINFOID=OracleHelper.ToLong(dr["REGINFOID"].ToString());
				}
				if(dr["TRADEBY"]!=null && dr["TRADEBY"].ToString()!="")
				{
					model.TRADEBY=dr["TRADEBY"].ToString();
				}
				if(dr["FORHOUTYPE"]!=null && dr["FORHOUTYPE"].ToString()!="")
				{
                    model.FORHOUTYPE = OracleHelper.ToInt(dr["FORHOUTYPE"].ToString());
				}
				if(dr["BUSSTYPE"]!=null && dr["BUSSTYPE"].ToString()!="")
				{
                    model.BUSSTYPE = OracleHelper.ToInt(dr["BUSSTYPE"].ToString());
				}
				if(dr["HOUADD"]!=null && dr["HOUADD"].ToString()!="")
				{
					model.HOUADD=dr["HOUADD"].ToString();
				}
				if(dr["TENRIGHT"]!=null && dr["TENRIGHT"].ToString()!="")
				{
					model.TENRIGHT=dr["TENRIGHT"].ToString();
				}
				if(dr["TENBANK"]!=null && dr["TENBANK"].ToString()!="")
				{
					model.TENBANK=dr["TENBANK"].ToString();
				}
				if(dr["TENSUBBACK"]!=null && dr["TENSUBBACK"].ToString()!="")
				{
					model.TENSUBBACK=dr["TENSUBBACK"].ToString();
				}
				if(dr["TENENDDATE"]!=null && dr["TENENDDATE"].ToString()!="")
				{
					model.TENENDDATE=DateTime.Parse(dr["TENENDDATE"].ToString());
				}
				if(dr["TENLEFTAMT"]!=null && dr["TENLEFTAMT"].ToString()!="")
				{
					model.TENLEFTAMT=OracleHelper.ToDecimal(dr["TENLEFTAMT"].ToString());
				}
				if(dr["HOUPRICE"]!=null && dr["HOUPRICE"].ToString()!="")
				{
					model.HOUPRICE=OracleHelper.ToDecimal(dr["HOUPRICE"].ToString());
				}
				if(dr["HOUTOTALPRICE"]!=null && dr["HOUTOTALPRICE"].ToString()!="")
				{
					model.HOUTOTALPRICE=OracleHelper.ToDecimal(dr["HOUTOTALPRICE"].ToString());
				}
				if(dr["DOWNPAYAMT"]!=null && dr["DOWNPAYAMT"].ToString()!="")
				{
					model.DOWNPAYAMT=OracleHelper.ToDecimal(dr["DOWNPAYAMT"].ToString());
				}
				if(dr["FIRSTPAYAMT"]!=null && dr["FIRSTPAYAMT"].ToString()!="")
				{
					model.FIRSTPAYAMT=OracleHelper.ToDecimal(dr["FIRSTPAYAMT"].ToString());
				}
				if(dr["PAYMOD"]!=null && dr["PAYMOD"].ToString()!="")
				{
					model.PAYMOD=dr["PAYMOD"].ToString();
				}
				if(dr["PAYBANK"]!=null && dr["PAYBANK"].ToString()!="")
				{
					model.PAYBANK=dr["PAYBANK"].ToString();
				}
				if(dr["PAYSUBBANK"]!=null && dr["PAYSUBBANK"].ToString()!="")
				{
					model.PAYSUBBANK=dr["PAYSUBBANK"].ToString();
				}
				if(dr["PROMISEAMT"]!=null && dr["PROMISEAMT"].ToString()!="")
				{
					model.PROMISEAMT=OracleHelper.ToDecimal(dr["PROMISEAMT"].ToString());
				}
				if(dr["COUGUA1"]!=null && dr["COUGUA1"].ToString()!="")
				{
					model.COUGUA1=dr["COUGUA1"].ToString();
				}
				if(dr["VERIFILD1"]!=null && dr["VERIFILD1"].ToString()!="")
				{
					model.VERIFILD1=dr["VERIFILD1"].ToString();
				}
				if(dr["COUGUA2"]!=null && dr["COUGUA2"].ToString()!="")
				{
					model.COUGUA2=dr["COUGUA2"].ToString();
				}
				if(dr["VERIFILD2"]!=null && dr["VERIFILD2"].ToString()!="")
				{
					model.VERIFILD2=dr["VERIFILD2"].ToString();
				}
				if(dr["SIGNMAN"]!=null && dr["SIGNMAN"].ToString()!="")
				{
					model.SIGNMAN=dr["SIGNMAN"].ToString();
				}
				if(dr["SPAREFIELD1"]!=null && dr["SPAREFIELD1"].ToString()!="")
				{
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
				}
				if(dr["SPAREFIELD2"]!=null && dr["SPAREFIELD2"].ToString()!="")
				{
					model.SPAREFIELD2=dr["SPAREFIELD2"].ToString();
				}
				if(dr["SPAREFIELD3"]!=null && dr["SPAREFIELD3"].ToString()!="")
				{
					model.SPAREFIELD3=dr["SPAREFIELD3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_APP_PROFORHOUINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_APP_PROFORHOUINFO sModel = new GSLMS.Entity.TB_APP_PROFORHOUINFO();
			string sql = "";
			sql = "select * from TB_APP_PROFORHOUINFO where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_APP_PROFORHOUINFO> GetList(GSLMS.Entity.TB_APP_PROFORHOUINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_APP_PROFORHOUINFO>();
			DataTable dt = null;
			string tblName = "TB_APP_PROFORHOUINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_APP_PROFORHOUINFO model = new GSLMS.Entity.TB_APP_PROFORHOUINFO();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

